package com.service.lotterySystem.service.impl;


import com.service.lotterySystem.service.ExcelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @program: CloudCampusEcology
 * @description:
 * @author: rui
 * @create: 2020-11-12 11:10
 **/
@Slf4j
@Service
public class ExcelServiceImpl implements ExcelService {
    //@Value("${spring.excel.filepath}")
    private String filepath; //邮件发送者
    @Autowired
    public StringRedisTemplate stringRedisTemplate;

//
//    @Override
//    public List<NameListDto> batchImport(MultipartFile file) throws Exception {
//
//
//        /*
//         * 判断文件名的合法性
//         * 判断文件是2003版or2007版
//         */
//        String fileName = file.getOriginalFilename();
//        String[] fullName = null;
//        if (fileName != null) {
//            fullName = fileName.split("\\.");
//        }
//        //log.info(fullName[1]);
//        boolean isExcel2003 = true;
//        if (fullName != null) {
//            String suffix = fullName[1];
//            if (!suffix.equals("xls") && !suffix.equals("xlsx")) {
//                throw new Exception("上传不正确");
//            }
//            if (suffix.equals("xlsx")) {
//                isExcel2003 = false;
//            }
//        }
//        InputStream iStream = file.getInputStream(); //IO流
//        Workbook workbook = null; //创建工作簿
//        if (isExcel2003) {
//            workbook = new HSSFWorkbook(iStream); //2003版
//        } else {
//            workbook = new XSSFWorkbook(iStream); //2007版
//        }
//        //将文件存储到本地
//        String savePath = null;
//        try {
//            savePath = filepath + fileName;
//            log.info(savePath);
//            OutputStream os = new FileOutputStream(savePath); // 保存到当前路径savePath
//            workbook.write(os);
//            os.flush();
//            os.close();
//        } catch (Exception e) {
//            log.error("File saving error !");
//            e.printStackTrace();
//        }
//        Workbook workbook2 = WorkbookFactory.create(file.getInputStream());
//        Sheet sheet = workbook2.getSheetAt(0);
//        //ExcelUtil<NameListDto> util = new ExcelUtil<>(NameListDto.class);
//       // List<NameListDto> nameListDtoList = util.importExcel(sheet.getSheetName(), workbook2, 2);
//        return null;
//    }
}
